package com.pretty.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.baike.dto.BaikePageDTO;
import com.pretty.test.controller.pets.baike.vo.BaikeDashboardSimpleListVO;
import com.pretty.test.controller.pets.baike.vo.BaikeDashboardVO;
import com.pretty.test.controller.pets.baike.vo.BaikePageVO;
import com.pretty.test.controller.pets.baike.wrapper.BaikeDashboardSimpleListWrapper;
import com.pretty.test.entity.PetsBaike;
import com.pretty.test.mapper.PetsBaikeMapper;
import com.pretty.test.service.IPetsBaikeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pretty.test.utils.otherutils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 宠物百科服务实现类
 * @author dujianyu
 * @since 2021-04-06
 */
@Service
public class PetsBaikeServiceImpl extends ServiceImpl<PetsBaikeMapper, PetsBaike> implements IPetsBaikeService {

    @Override
    public IPage<BaikePageVO> selectBaikePage(Page<BaikePageVO> page, BaikePageDTO dto) {
        QueryWrapper queryWrapper  = new QueryWrapper();
        queryWrapper.eq("pb.is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getName()),"pb.name",dto.getName());
        queryWrapper.eq(!Func.isBlank(dto.getAnimalType()),"pb.animal_type",Func.toLongArray(dto.getAnimalType())[0]);
        queryWrapper.orderByDesc("pb.update_time");
        return baseMapper.selectBaikePage(page,queryWrapper);
    }

    @Override
    public List<BaikeDashboardVO> dashboardList() {
        return baseMapper.dashboardList();
    }

    @Override
    public List<BaikeDashboardSimpleListVO> dashboardSimpleList(BaikePageDTO dto) {
        QueryWrapper queryWrapper  = new QueryWrapper();
        queryWrapper.eq("pb.is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getName()),"pb.name",dto.getName());
        queryWrapper.orderByAsc("pb.animal_type");
        return baseMapper.dashboardSimpleList(queryWrapper);
    }
}
